
var rotate = function (nums, k) {
  let len = nums.length
  let arrChouli = []
  let arrLast = []
  for (let i = k; i > 0; i--) {
    arrChouli.push(nums[len-i]) 
  }
  for (let i = 0; i < len - k; i++) {
    arrLast.push(nums[i]) 
  }
  let arr = new Array(...arrChouli, ...arrLast)
  return arr
};

let newarr = rotate([1, 2, 3, 4, 5, 6, 7], 3)
console.log(newarr);